from RestAPI.core.APIwrapper import *
from RestAPI.core.APIExceptions import APIException
from Errors import *
import base64
import hmac
import time
import sys
if sys.version_info[:2] > (2, 4): # pragma: no cover
    from urllib2 import quote
    from hashlib import sha256 # pylint: disable-msg=E0611
else:
    from urllib import quote
    from Crypto.Hash import SHA256 as sha256



class AWS(APIwrapper):
    """
    Abstract class for all amazon webservices.
    """
    reserved=['Service','AWSAccessKeyId']
    def setAuthKey(self,key):
        self.AuthKey=key
    def setSecretKey(self,secretkey):
        self.SecretAccessKey=secretkey
    def setAssociateTag(self,associateKey):
        self.AssociateTag=associateKey
    def getSignature(self,stringTosign):
        if not hasattr(self,'SecretAccessKey'):
            raise NoSecretAccessKey()
        return base64.b64encode(hmac.new(self.SecretAccessKey,stringTosign,sha256).digest()).replace('+','%2B').replace('=','%3D')
    def getStringToSign(self):
        pass

